package com.yonyou.pmclouds.basecom.entity;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class AdditionalPropertiesVOWrapper<T> implements Serializable {
    //留言数量
    public static final String COMMENT_COUNT = "commentCount";
    @JsonUnwrapped
    private T wrapped;
    @JsonUnwrapped
    private Map<String, Object> additional;

    public AdditionalPropertiesVOWrapper(T wrappedVO) {
        this.wrapped = wrappedVO;
        this.additional = new HashMap<>();
    }

    /**
     * 向包装器中添加属性，如果属性存在则会被替换
     * 注意： object需要能被调用方反序列化
     */
    public void addProperties(String property, Object value) {
        additional.put(property, value);
    }

    public void removeProperties(String property) {
        additional.remove(property);
    }

    public void putCommentCount(Integer count) {
        additional.put(COMMENT_COUNT, count);
    }

    public Integer fetchCommentCount() {
        return (Integer) additional.get(COMMENT_COUNT);
    }
}
